<template>
  <div class="strut-div">
    <div class="building-window">
      <div class="building-title">基本农田现有面积统计</div>
      <div class="build-main">
        <div class="num-chart">
          <div class="num-circle">
            <p class="num">
              <coun-to :end="farmlandArea"></coun-to>
            </p>
            <p class="txt">万亩</p>
          </div>
        </div>
      </div>
    </div>
    <div class="window-item industry-window">
      <div class="window-title">
        <img src="@/assets/imgs/tg/menu-icon.png" alt="menu" />
        基本农田侵占面积统计
      </div>
      <div class="window-main">
        <common-pieNew-chart ref="rsPlantingPie" :config='rsPlantingPieConfig'></common-pieNew-chart>
      </div>
    </div>
    <div class="window-item economic-window">
      <div class="window-title">
        <img src="@/assets/imgs/tg/menu-icon.png" alt="menu" />
        侵占类型总量对比
      </div>
      <div class="window-main">
        <common-mix-chart ref="rsPlantingBar" :config="rsPlantingBarConfig"></common-mix-chart>
      </div>
    </div>
  </div>
</template>
<script>
  import {
    mapGetters
  } from "vuex";
  import CounTo from '@/components/count-to';
  import CommonPieNewChart from '@/components/common/common-pieNew-chart.vue';
  import CommonBarChart from '@/components/common/common-bar-chart.vue';
  import CommonMixChart from "@/components/common/common-mix-chart.vue";

  export default {
    name: "ng-rs-left",
    components: {
      CounTo,
      CommonPieNewChart,
      CommonBarChart,
      CommonMixChart
    },
    computed: {
      ...mapGetters(["remote_data"])
    },
    data() {
      return {
        farmlandArea: 0,
        rsPlantingPieConfig: {
          option: {
            title: '',
            id: 'rsPlantingPie',
            color: ['#19AEF1', '#AC4BFC', '#EDA652', '#08C49A', '#7264F7', '#00EAFF'],
            tooltip: {
              show: true, //防止鼠标移到不需要的数据上弹出label
              trigger: 'item',
              formatter: "{a} {b} : {c} ({d}%)"
            },
            legend: {
              show: true,
              x: "0%",
              y: "bottom",
              orient: 'vertical',
              textStyle: {
                color: ['#19AEF1', '#AC4BFC', '#EDA652', '#08C49A', '#7264F7', '#00EAFF'],
                fontSize: 14,
              },
              padding: 20,
              itemGap: 14,
              data: []
            },
            series: [{
              name: '',
              type: 'pie',
              radius: 100,
              center: ['50%', '40%'],
              label: {
                // color: "#fff",
                formatter: '{a} {b}:{d}%',
                fontSize: 16
              },
              labelLine: {
                length: 10,
                length2: 20,
              },
              data: []
            }]
          }
        },
        rsPlantingBarConfig: {
           option: {
            id: 'rsPlantingBar',
            legend: {
              data: [],
              right: 0
            },
            xAxis: [],
            yAxis: [{
                type: 'value',
                name: '亩',
                min: 0,
                max: null,
                interval: 0.5,
                axisLabel: {
                  formatter: '{value}'
                },
                splitLine: {
                  show: false
                }, //去除网格线
              },
              {
                show: false,
              }
            ],
            series: [{
                name: '固话',
                type: 'bar',
                data: [5.15, 6.14, 4.04, 2.78, 1.89],
                color: {
                  type: 'linear',
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [{
                    offset: 0,
                    color: '#FBCC13' // 0% 处的颜色
                  }, {
                    offset: 1,
                    color: '#FBCC13' // 100% 处的颜色
                  }],
                },
                // barWidth: 18, //柱图宽度
              },
              {
                name: '移动电话',
                type: 'bar',
                data: [50.80, 49.48, 51.95, 55.63, 57.43],
                color: {
                  type: 'linear',
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [{
                    offset: 0,
                    color: '#3FECFF' // 0% 处的颜色
                  }, {
                    offset: 1,
                    color: '#00FCEB' // 100% 处的颜色
                  }],
                },
                // barWidth: 18, //柱图宽度
              },
              {
                name: '移动电话',
                type: 'bar',
                data: [50.80, 49.48, 51.95, 55.63, 57.43],
                color: {
                  type: 'linear',
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [{
                    offset: 0,
                    color: '#7494fb' // 0% 处的颜色
                  }, {
                    offset: 1,
                    color: '#584cf8' // 100% 处的颜色
                  }],
                },
                // barWidth: 18, //柱图宽度
              }
            ]
          }
        }
      }
    },
    mounted() {
      setTimeout(() => {
        this.initData();
      },2000);
    },
    methods: {
      initData() {
        this.farmlandArea = this.remote_data.filter(item => item.boxNum == '0101')[0].data[0].data[0].value;

        let _plantingPieData = this.remote_data.filter(item => item.boxNum == '0102')[0].data;
        this.rsPlantingPieConfig.option.legend.data = _plantingPieData.map(item => item.name);
        this.rsPlantingPieConfig.option.series[0].data = _plantingPieData.map(item => {
          return {
            name: item.name,
            value: item.data[0].value
          }
        });

        this.$refs.rsPlantingPie.initChart();

        let _plantingMixData = this.remote_data.filter(item => item.boxNum == '0103')[0].data;
        this.rsPlantingBarConfig.option.legend.data = _plantingMixData.map(item => item.name);
        this.rsPlantingBarConfig.option.xAxis = _plantingMixData[0].data.map(item => item.name);

        _plantingMixData.forEach((item,index) => {
          this.rsPlantingBarConfig.option.series[index].name = item.name;
          this.rsPlantingBarConfig.option.series[index].data = item.data.map(v => v.value);
        });

        this.$refs.rsPlantingBar.initChart();
      }
    }
  }

</script>
<style lang="scss" scoped>
  .building-window {
    width: 500px;
    height: 270px;
    background: url("../../../assets/imgs/tg/leftop-window.png") no-repeat center center;
    background-size: 100% 100%;
    float: right;

    .building-title {
      width: 100%;
      height: 68px;
      line-height: 68px;
      padding-left: 36px;
      font-size: 22px;
      color: #aaddff;
    }

    .build-main {
      .num-chart {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0 26px 0 62px;

        .num-circle {
          display: flex;
          justify-content: center;
          align-items: center;
          flex-direction: column;
          width: 180px;
          height: 180px;
          background: url("../../../assets/imgs/tg/circle-bg.png");
          background-size: cover;

          .num {
            font-size: 40px;
            font-weight: bold;
            color: #f7cc49;
          }

          .txt {
            font-size: 18px;
            color: #aaddff;
          }
        }
      }

      .desc-box {
        height: 100px;

        .desc-txt {
          width: 94px;
          font-size: 20px;
          color: #aaddff;
          text-align: center;
        }

        @extend .num-chart
      }
    }
  }

  .window-item {
    width: 470px;
    background: url("../../../assets/imgs/tg/chart-window-v2.png") no-repeat;
    background-size: 100% 100%;

    .window-title {
      height: 70px;
      line-height: 70px;
      font-size: 22px;
      color: #aaddff;
      padding-left: 20px;

      >img {
        vertical-align: middle;
      }
    }

    .window-main {
      height: calc(100% - 70px);
    }
  }

  .industry-window {
    height: 380px;
    float: right;
    margin-top: 20px;
  }

  .economic-window {
    height: 300px;
    float: right;
    margin-top: 20px;
  }

</style>
